<?php

include '../../db.php';
$connect = pg_connect($connectionString);
if (!$connect) {
    echo "connect : A connection to the server could not be established!";
    return false;
}

$params = array();
array_push($params, pg_escape_string($_POST["serie"]));
array_push($params, pg_escape_string($_POST["number"]));
array_push($params, pg_escape_string($_POST["supplier_id"]));
array_push($params, pg_escape_string($_POST["emission_date"]));
array_push($params, pg_escape_string($_POST["cancellation_date"]));
array_push($params, pg_escape_string($_POST["subtotal"]));
array_push($params, pg_escape_string($_POST["igv"]));
array_push($params, pg_escape_string($_POST["total"]));

$stmt = pg_prepare($connect, "create_purcharse_header", "INSERT INTO purcharse_header(serie,number,supplier_id,emission_date,cancellation_date,subtotal,igv,total) VALUES ($1,$2,$3,$4,$5,$6,$7,$8);");
$result = pg_execute($connect, "create_purcharse_header", $params);

if (!$result) {
    die("Error in SQL query: " . pg_last_error());
}
pg_free_result($result);
pg_close($connect);